﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MbUnit.Framework;
using DeSleeper.Library.PowerManagement;

namespace DeSleeper.Tests
{
	[TestFixture]
	public class PowerSchemeFixture
	{
		[Test, Explicit("Varies from PC to PC.  Default on Vista is 4.")]
		public void Enumerate()
		{
			var count = 0;
			foreach (var scheme in PowerScheme.GetPowerSchemes())
			{
				Assert.IsNotNull(scheme.Name);
				count++;
			}
			Assert.AreEqual(4, count);
		}

		[Test]
		public void Current()
		{
			var scheme = PowerScheme.GetCurrent();
			Assert.IsNotNull(scheme);
		}

		[Test]
		public void Update()
		{
			var scheme = PowerScheme.GetPowerSchemes().First();
			var before = scheme.ACSettings.IdleTimeout;
			var expected = before + new TimeSpan(0, 0, 10, 0);
			scheme.ACSettings.IdleTimeout = expected;
			scheme.Update();

			var updated = PowerScheme.GetPowerSchemes().First();
			Assert.AreNotEqual(before, updated.ACSettings.IdleTimeout);
			Assert.AreEqual(expected, updated.ACSettings.IdleTimeout);

			scheme.ACSettings.IdleTimeout = before;
			scheme.Update();

			updated = PowerScheme.GetPowerSchemes().First();
			Assert.AreEqual(before, updated.ACSettings.IdleTimeout);
		}

	}
}